﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BasketStats.Core.Stats;

namespace BasketStats.Core.Team
{
    public class Player
    {
        private ICollection<Statistics> m_gameStatistics = new List<Statistics>();

        public Player()
        {
            Info = PlayerInfo.Empty;
        }

        public PlayerInfo Info { get; set; }

        public Statistics CurrentStatistics 
        {
            get
            {
                return m_gameStatistics.LastOrDefault();
            }
            internal set
            {
                if (value != null)
                {
                    m_gameStatistics.Add(value);
                    value.PropertyChanged += (o, e) => RaisePlayerStatsChanged();
                }
            } 
        }

        public IEnumerable<Statistics> GameStatistics
        { 
            get 
            { 
                return m_gameStatistics; 
            } 
        }

        private void RaisePlayerStatsChanged()
        {
            if (PlayerStatsChanged != null)
            {
                PlayerStatsChanged(this, EventArgs.Empty);
            }
        }

        public event EventHandler PlayerStatsChanged;
    }
}
